<?php
namespace app\api\controller;
use think\Request;
use app\api\controller\Base;
use app\api\model\User as Muser;

/**
 * @title user 小程序商城用户接口|[客户端]
 * @description 与小程序商城用户有关的信息
 */
 
class User extends Base
{
    /**
     * @title user/get_captcha 获取验证码 GET
     * @description 说明：依据 手机号码发送短信至手机
	 * openid 密码 注意加密存储
	 * @author 虾哥@2424899422@qq.com
	 * @url user/get_captcha/
	 * @Turl api/user/get_captcha
	 * @param name:tel_phone type:strying require:1 default:null other: desc: 一个手机号码一天最多可获取三条
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为新增行数
     * 
     */
    public function get_captcha() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'create user success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = Muser::cartAdd($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'create user failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
	}
	
	/*
	
			
			//$send_phone = '17620355825';
			//您好,我是 ${defined_name}，联系方式 ${defined_cusphone}。我要报案,相关信息已提交至系统,出险人${defined_aciperson},请知悉。
			
			$defined_name = $session['dw_name'].' 的 '.$post['report_person'];
			$defined_cusphone = $post['report_phone'];
			$defined_aciperson = $post['accident_person'];

			$temp_id = "SMS_69110113";
			$send_content = "{\"defined_name\":\"".$defined_name."\",\"defined_cusphone\":\"".$defined_cusphone."\",\"defined_aciperson\":\"".$defined_aciperson."\"}";
			//var_dump($send_content);
			//var_dump($send_phone);
			//exit;
			//调用阿里大鱼短信接口  一通

			
			
			$sms_result = $this->sms_model->sms_alidayu_wx($temp_id,$send_content, $send_phone);
			
			if(isset($sms_result->result->success) && $sms_result->result->success){
				$send_result = 0;
				$send_status = "发送成功";
			}else if(isset($sms_result->sub_msg)){
				$send_result = 1;
				$send_status = $sms_result->sub_msg;
			}else {
				$send_result = 2;
				$send_status = "未知错误";
			}
			
			//echo $send_result;
			//var_dump($sms_result);exit;
			// 更新数据库
			$new_id = $this->db->insert('report_send_message',array(
				'policy_report_id'=>$id,
				'user_id'=>$user_id,
				'send_content'=>$send_content,
				'send_number'=>$send_phone,
				'send_result'=>$send_result,
				'send_status'=>$send_status)
				);
			
	*/
	
	/**
     * @title user/create 创建小程序商城用户 POST
     * @description 说明：依据 手机验证码| 微信openid 创建用户|
	 * openid 密码 注意加密存储
	 * @author 虾哥@2424899422@qq.com
	 * @url user/create/
	 * @Turl api/user/create

	 * @param name:tel_phone type:strying require:0 default:null other: desc:手机号码与系统不能重复
	 * @param name:captcha type:strying require:1 default:null other: desc:验证码
	 * @param name:openid type:strying require:1 default:null other: desc:openid
	 * @param name:pass_word type:string require:0 default:null other: desc:密码
	 * @param name:login_name type:string require:0 default:null other: desc:登录名称与系统不能重复

	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为新增行数
     * 
     */
    public function create() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'create user success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = Muser::cartAdd($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'create user failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
	}
	
	/**
     * @title user/login 用户登录小程序商城 POST
     * @description 说明：依据 微信openid 直接登录 | 用户名+密码登录 | 手机号+密码登录 |
	 * openid 密码 注意加密存储
	 * @author 虾哥@2424899422@qq.com
	 * @url user/create/
	 * @Turl api/user/create
	 
	 * @param name:login_type type:strying require:0 default:0 other: desc:登录类型|0--openid|1用户名+密码|2手机号+密码|
	 * @param name:tel_phone type:strying require:0 default:null other: desc:手机号码与系统不能重复
	 * @param name:openid type:strying require:1 default:null other: desc:openid
	 * @param name:pass_word type:string require:0 default:null other: desc:密码
	 * @param name:login_name type:string require:0 default:null other: desc:登录名称与系统不能重复

	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为新增行数
     * 
     */
    public function login() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'create user success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = Muser::cartAdd($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'create user failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
	}
	
	/**
     * @title user/logout 用户退出小程序商城 GET
     * @description 说明：用户退出小程序商城 
	 * @author 虾哥@2424899422@qq.com
	 * @url user/logout/
	 * @Turl api/user/logout

	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为新增行数
     * 
     */
    public function logout() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'create user success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = Muser::cartAdd($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'create user failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
	}
	
	/**
     * @title user/update 用户修改相关个人信息
     * @description 说明：用户退出小程序商城 
	 * @author 虾哥@2424899422@qq.com
	 * @url user/update/
	 * @Turl api/user/update
	 
	 * @param name:login_type type:strying require:0 default:0 other: desc:登录类型|0--openid|1用户名+密码|2手机号+密码|
	 * @param name:tel_phone type:strying require:0 default:null other: desc:手机号码与系统不能重复
	 * @param name:openid type:strying require:1 default:null other: desc:openid
	 * @param name:pass_word type:string require:0 default:null other: desc:密码
	 * @param name:user_sex type:strying require:0 default:0 other: desc:性别|0女|1男|
	 * @param name:user_email type:strying require:0 default:null other: desc:邮箱
	 * @param name:user_photo type:strying require:1 default:null other: desc:会员头像
	 * @param name:nick_name type:strying require:0 default:null other: desc:用户昵称
	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为新增行数
     * 
     */
    public function update() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'create user success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = Muser::cartAdd($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'create user failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
	}
	

}
